using System;
using System.IO;
using System.Web;
using System.Data;
using System.Threading;
using System.Collections;
using System.ComponentModel;
using ACM.cmsarea08.mainconfiguration;
using ACM.cmsarea08.DBManager;
using ACM.cmsarea08.Function;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Web.Security;
using System.Web.Caching;

namespace ACM.cmsarea08.Function.Search
{

//	public class TitoloSuggestOrder:IComparer
//	{
//		public int Compare(object a,object b)
//		{
//			return Comparer.Default.Compare(((TitoloSuggest)a).punti,((TitoloSuggest)b).punti);
//		}
//	}

	public class ArrayListKeyAscend:IComparer
	{
		public int Compare(object a,object b)
		{
			return Comparer.Default.Compare(((DictionaryEntry)a).Key,((DictionaryEntry)b).Key);
		}
	}
	public class ResultListKeyAscend:IComparer
	{
		public int Compare(object a,object b)
		{
			return Comparer.Default.Compare(((RisultsLens)a).punti,((RisultsLens)b).punti);
		}
	}
	public class RisultatiGrezziKeyDescend:IComparer
	{
		public int Compare(object a,object b)
		{
			return Comparer.Default.Compare(((RisultatiGrezzi)b).Punti,((RisultatiGrezzi)a).Punti);
		}
	}

	public class DiamanteListKeyDescend:IComparer
	{
		public int Compare(object a,object b)
		{
			return Comparer.Default.Compare(((RisultatiDiamante)b).punti,((RisultatiDiamante)a).punti);
		}
	}
	public class DiamanteVerifica:IComparer
	{
		public int Compare(object a,object b)
		{
			return Comparer.Default.Compare(((RisultatiDiamante)b).isbn,((RisultatiDiamante)a).isbn);
		}
	}
	public class RisultatiDiamante {
		public double punti ;
		public string misbn;
		public string mtitolo;
		public string mautore;
		public double mprezzo;
		public string msoglia;
		public string mgiacenza;
		public string minelenco;
		public string mprocodice;
		public string mNT;
		public string mdewey;
		public string meditore;
		public string mpubstatus;
		public string miscartable;
		public string is_sante;
		
		public RisultatiDiamante() {
			mtitolo = "";
			mautore = "";
			mprezzo = 0;
		}
		
		public RisultatiDiamante(double i, string isb) {
			punti = i;
			isbn = isb;
			mtitolo = "";
			mautore = "";
			mprezzo = 0;			
		}

		public string isbn {
			get {
				return misbn;
			}
			set {
				misbn = value;
			}
		}
		public string titolo {
			get {
				return mtitolo;
			}
		}
		public string autore {
			get {
				return mautore;
			}
		}
		public string prezzo {
			get {
				return mprezzo.ToString();
			}
		}
		public double Attinenza {
			get {
				return punti;
			}
		}		
		public string soglia {
			get {
				return msoglia;
			}
		}
		public string giacenza {
			get {
				return mgiacenza;
			}
		}
		public string inelenco {
			get {
				return minelenco;
			}
		}
		public string pro_codice {
			get {
				return mprocodice;
			}
		}	
		public string notificationtype {
			get {
				return mNT;
			}
		}			
		public string editore {
			get {
				return meditore;
			}
		}			
		public string dewey {
			get {
				return mdewey;
			}
		}					
		public string publishingstatus {
			get {
				return mpubstatus;
			}
		}			
		public string isCartable {
			get {
				return miscartable;
			}
		}			
		public string isSante {
			get {
				return is_sante;
			}
		}			

	}
	public class RisultsLens {
		//: IComparable ;
		public string parola;
		public double punti;
		public string isbn;
		public RisultsLens() { }
		public RisultsLens(string par, double pu, string isb) {
			parola = par;
			punti = pu;
			isbn = isb;
		}
		/*
		public int CompareTo(object o) {
			if(o is RisultsLens)
				return punti.CompareTo(((RisultsLens)o).punti);
			else
				return -1;
		}
		*/
	}
	public class RisultatiGrezzi {
		private string parola;
		private string forse;
		private double punti;
		private string isbns;
		public RisultatiGrezzi() { 
			parola="";
			forse = "";
			punti =0;
			isbns = "";
		}
		public string Parola {
			get {
				return parola;
			}
			set {
				parola = value;
			}
		}
		public string Forse {
			get {
				return forse;
			}
			set {
				forse = value;
			}
		}
		
		public string Isbns {
			get {
				return isbns;
			}
			set {
				isbns = value;
			}
		}		
		public double Punti {
			get {
				return punti;
			}
			set {
				punti = value;
			}
		}
		
		
		
		
	}
	
	[Serializable]
	public class SearchParams {
		private string mtesto;
		private string[] _modules;
		private TipoRicerca _searchMode;
		private bool _searchByTAG;
		private bool _searchByTitle;
		private bool _searchByText;
		private bool _searchBySections;
		private bool _searchByCategories;
		private bool _searchWithWildCards;
		
		public bool SearchByTAG {
			get {
				return _searchByTAG;
			}
			set {
				_searchByTAG = value;
			}
		}
		public bool SearchByTitle {
			get {
				return _searchByTitle;
			}
			set {
				_searchByTitle = value;
			}
		}
		public bool SearchByText {
			get {
				return _searchByText;
			}
			set {
				_searchByText = value;
			}
		}
		public bool SearchBySections {
			get {
				return _searchBySections;
			}
			set {
				_searchBySections = value;
			}
		}		
		public bool SearchByCategories {
			get {
				return _searchByCategories;
			}
			set {
				_searchByCategories = value;
			}
		}
		public bool SearchWithWildCards {
			get {
				return _searchWithWildCards;
			}
			set {
				_searchWithWildCards = value;
			}
		}
		public TipoRicerca SearchMode {
			get {
				return _searchMode;
			}
			set {
				_searchMode = value;
			}
			
		}
	
		
		public string Testo {
			get {
				return mtesto;
			}
			set {
				mtesto = value;
			}
		}
		public string[] IdModules {
			get {
				return _modules;
			}
			set {
				_modules = value;
			}
		}
		
	
			
#region Contruttori		
		public SearchParams() {
			SearchByTAG = true;
			SearchByTitle = true;
			SearchByText = true;
			SearchBySections = false;
			SearchByCategories = false;
			SearchMode = TipoRicerca.Frase;
			Testo = "";
		}

		public SearchParams(string testo) {
			SearchByTAG = true;
			SearchByTitle = true;
			SearchByText = true;
			SearchBySections = true;
			SearchByCategories = true;
			SearchMode = TipoRicerca.Frase;
			Testo = testo;
			
		}
		public SearchParams(string testo, TipoRicerca tipoRicerca) {
			SearchByTAG = true;
			SearchByTitle = true;
			SearchByText = true;
			SearchBySections = false;
			SearchByCategories = false;
			SearchMode = tipoRicerca;
			Testo = testo;
			
		}
		
		
#endregion		
		public override string ToString()
		{
			return HttpUtility.HtmlDecode(mtesto);
		}
		
		public bool IsValid() {
			if(mtesto.Trim().Length>0)
				return true;
		
			return false;			
		}
	
	}

	public class SearchParamElaborato {
		#region privati
		private string mtesto;
		private int mtestoC;
		private string meditore;
		private int meditoreC;
		private string mdewey;
		private string mprezzo;
		private string misbn;
		private string filtc;
		private string filtt;
		private string fraseric;
		private bool istitle;
		private bool or_mode;
		
		private SearchFilters[] filtsc;
		#endregion
		public bool OrMode {
			get {
				return or_mode;
			}
			set {
				or_mode = value;
			}
		}		
		public string FraseSalvezza {
			get {
				return fraseric;
			}
			set {
				fraseric = value;
			}
		}
		
		public string Isbn {
			get {
				return misbn;
			}
			set {
				misbn = value;
			}
		}
		public bool isTitle {
			get {
				return istitle;
			}
			set {
				istitle = value;
			}
		}
		public string FilterCode {
			get {
				return filtc;
			}
			set {
				filtc = value;
			}
		}
		public string FilterText {
			get {
				return filtt;
			}
			set {
				filtt = value;
			}
		}		
		public string Testo {
			get {
				return mtesto;
			}
			set {
				mtesto = value;
			}
		}
		public string Editore {
			get {
				return meditore;
			}
			set {
				meditore = value;
			}
		}		
		public string Dewey {
			get {
				return mdewey;
			}
			set {
				mdewey = value;
			}
		}		
		public string Prezzo {
			get {
				return mprezzo;
			}
			set {
				mprezzo = value;
			}
		}		
		public int TestoC {
			get {
				return mtestoC;
			}
			set {
				mtestoC = value;
			}
		}		
		public int EditoreC {
			get {
				return meditoreC;
			}
			set {
				meditoreC = value;
			}
		}	
		public SearchFilters[] Filters {
			get {
				return filtsc;
			}
			set {
				filtsc = value;
			}			
		}

		public SearchParamElaborato() {
			istitle=true;
			mprezzo = "0";
			filtc = "";
			filtt = "";
			mdewey ="";
			meditore = "";
			misbn = "";
			mtesto = "";
			mtestoC = 0;
			meditoreC = 0;
			//filtsc = new SearchFilters[0];
			filtsc = new SearchFilters[0];
		}

		public bool IsValid() {
			if(mtesto.Trim().Length>0)
				return true;
			if(meditore.Trim().Length>0)
				return true;
			if(mdewey.Trim().Length>0)
				return true;
			if(misbn.Trim().Length>0)
				return true;
			return false;			
		}
	}
	
	
	public class MiniResultContainer {
		private ArrayList autori;
		private ArrayList editori;
		private ArrayList prezzi;
		private ArrayList dewey;
		public MiniResultContainer() { }
		public ArrayList Autori {
			get {
				if(autori==null)
					return new ArrayList();
				else
				return autori;
			}
		}
		public ArrayList Editori {
			get {
				if(editori==null)
					return new ArrayList();
				else
					return editori;
			}
		}		
		public ArrayList Prezzo {
			get {
				if(prezzi==null)
					return new ArrayList();
				else
				return prezzi;
			}
		}		
		public ArrayList Dewey {
			get {
				if(dewey==null)
					return new ArrayList();
				else
					return dewey;
			}
		}		

		public void setAutori (ArrayList au) {
			autori = au;
		}
		public void setEditori (ArrayList ed) {
			editori = ed;
		}
		public void setPrezzi (ArrayList pr) {
			prezzi = pr;
		}
		public void setDewey (ArrayList dw) {
			dewey = dw;
		}
		
	}
	
	[Serializable]
	public class SearchFilters : System.Xml.Serialization.IXmlSerializable {
		private string _code;
		private string _text;
		private string _desc;
		public string Code {
			get {
				return _code;
			}
			set {
				_code = value;
			}
		}
		public string Text {
			get {
				return _text;
			}
			set {
				_text = value;
			}
		}		
		public string Descrizione {
			get {
				return _desc;
			}
			set {
				_desc = value;
			}
		}		
		public SearchFilters () { _code=""; _text="";_desc="";}
		public SearchFilters (string newCode, string newText) { _desc="";_code=newCode; _text=newText;}

    // Xml Serialization Infrastructure
    public void WriteXml (System.Xml.XmlWriter writer)
    {
    	writer.WriteAttributeString("_code",_code);
    	writer.WriteAttributeString("_text",_text);
    	writer.WriteAttributeString("_desc",_desc);
    }

    public void ReadXml (System.Xml.XmlReader reader)
    {
        if(reader.GetAttribute("_code")!=null)
        	_code = reader.GetAttribute("_code").ToString();
        else
        	_code = "";
        if(reader.GetAttribute("_text")!=null)
        	_text = reader.GetAttribute("_text").ToString();
        else
        	_text = "";
        if(reader.GetAttribute("_desc")!=null)
        	_desc = reader.GetAttribute("_desc").ToString();
        else
        	_desc = "";        
        
        
    }

    public System.Xml.Schema.XmlSchema GetSchema()
    {
        return(null);
    }		
		
	}
	
	public enum TipoRicerca {
		Frase = 0,
		Tutte=1,
		Ciascuna = 2,
		NoResult = -1
	}

	
}
	
	
	
	
